/*
 * @lc app=leetcode.cn id=541 lang=typescript
 *
 * [541] 反转字符串 II
 */

// @lc code=start
function reverseStr(s: string, k: number): string {
    let final = "";
    let count = 1;
    while (count <= s.length) {
        // 补全最后的 count 到 2*k 的倍数
        if (count === s.length) {
            while (count % (2 * k)) {
                count++;
            }
        }
        if (!(count % (2 * k))) {
            const last = s.slice(count - 2 * k, count);
            const front = last.slice(0, k).split("").reverse().join("");
            const result = front + last.slice(k);
            console.log(result, front);
            final = final + result;
        }

        count++;
    }
    return final;
}
// @lc code=end
